﻿/* 
 * Rug.Cmd part of Rugland Console Framework
 * 
 * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, 
 * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED 
 * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
 * 
 * Copyright (C) 2008 Phill Tew. All rights reserved.
 * 
 */

using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Drawing;

namespace Rug.Cmd
{
    /// <summary>
    /// Version 1.0.0.0
    /// </summary>
    public partial class Helper
    {
        #region Node helpers

        public static XmlNode FindChild(XmlNode node, string name)
        {
            return node.SelectSingleNode(name);
        }

        public static XmlElement AppendChild(XmlElement element, string name)
        {
            if (IsNotNullOrEmpty(name) && element != null)
            {
                XmlElement el = element.OwnerDocument.CreateElement(name);

                element.AppendChild(el);

                return el;
            }

            return null;
        }

        public static void AppendAttributeAndValue(XmlElement element, string name, string value)
        {
            if (IsNotNullOrEmpty(value))
            {
                element.Attributes.Append(element.OwnerDocument.CreateAttribute(name));
                element.Attributes[name].Value = value;
            }
        }

        public static string GetAttributeValue(XmlNode node, string name, string @default)
        {
            if ((node.Attributes[name] != null))
                return node.Attributes[name].Value;
            else
                return @default;
        }

        public static bool HasAttribute(XmlNode node, string name)
        {
            return node.Attributes[name] != null;
        }

        #endregion
    }
}